package com.cy.order.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.math.BigDecimal;

@LocalTCC
public interface OrderTccAction {
    //Try
    //第二阶段seata的一个bug，这里不传递封装的Order对象
    //而是一个一个的传递订单参数
    @TwoPhaseBusinessAction(/*两阶段事务命名，自定义，默认同接口名*/name = "OrderTccAction",
                            /*提交方法名：默认commit，可不加*/commitMethod = "commit",
                            /*回滚方法名：默认rollback，可不加*/rollbackMethod = "rollback")
    boolean prepare(/*上下文对象，可以在不同阶段传输数据*/
                    BusinessActionContext ctx,
                    /*@BusinessActionContextParameter将属性放到上下文对象中*/
                    @BusinessActionContextParameter(paramName = "orderId")Long orderId,
                    Long userId,
                    Long productId,
                    Integer count,
                    BigDecimal money);

    //Confirm
    boolean commit(BusinessActionContext ctx);

    //Cancel
    boolean rollback(BusinessActionContext ctx);
}
